/*
 * timestep.h
 *
 *  Created on: 04/09/2013
 *      Author: joserobertosteiner
 */

#ifndef TIMESTEP_H_
#define TIMESTEP_H_

void timestep(long, double, double*, double*, double[], double[], double[], double[]);

#endif /* TIMESTEP_H_ */

/*
 * timestep.c
 *
 *  Created on: 04/09/2013
 *      Author: joserobertosteiner
 */


#include <stdio.h>
#include "../Forcas/Forca_HMF.h"

/*
 * 	Os coeficientes abaixo s�o tirados do artigo de Yoshida
 */

#define  B0   0.675603595979828813
#define  B1  -0.175603595979828813
#define  D0   1.35120719195965763
#define  D1  -1.70241438391931525


void timestep(long n, double dt, double *magx, double *magy, double r[], double p[], double f[], double m[])
{
	long i;
	double mx,my;

	for ( i = 0 ; i < n ; i++ ){
		p[i] += B0*dt*f[i];
		r[i] += D0*dt*p[i];
	}

	forca(n,&mx,&my,r,f, m);
	for ( i = 0 ; i < n ; i++ ){
		p[i] += B1*dt*f[i];
		r[i] += D1*dt*p[i];
	}

	forca(n,&mx,&my,r,f, m);
	for ( i = 0 ; i < n ; i++ ){
		p[i] += B1*dt*f[i];
		r[i] += D0*dt*p[i];
	}

	forca(n,&mx,&my,r,f, m);
	for ( i = 0 ; i < n ; i++ ){
		p[i] += B0*dt*f[i];
	}

	*magx=mx;
	*magy=my;


	return;
}

